<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div>
        <h1>The Ajax 04 Page</h1>
        <fieldset>
            <legend>Ajax 表单请求</legend>
            <form enctype="application/x-www-form-urlencoded">
                <input id="name" type="text" name="name" onblur="doCheck()"/>
                <button type="button" onclick="doSave()">Save</button>
            </form>
            <span id="result"></span>
        </fieldset>
    </div>
    <script src="js/ajax.js"></script>
    <script>
        function doCheck() {
            //1.定义请求url
            var url="doCheck";
            //2.定义请求参数
            var name=document.forms[0].name.value;
            var params="name="+name;
            //3.发送异步Get请求
            Ajax.doAjaxGet(url,params,function(result){
                document.getElementById("result").innerHTML=result;
            })
        }

        function doSave() {
            //1.定义请求url
            var url="doSave";
            //2.定义请求参数
            var params="name="+document.forms[0].name.value;
            //3.发送异步的post请求
           Ajax.doAjaxPost(url,params,function(result){
                document.getElementById("result").innerHTML=result;
            })
        }
    </script>
</body>
</html>